<template>
  <div id="app">
    <!-- <div>
      <div class="recharge-container">
        <h2>充值</h2>
        <div class="amount-options">
          <button v-for="amount in amounts" :key="amount" :class="{ active: selectedAmount === amount }"
            @click="selectAmount(amount)">
            ¥{{ amount }}
          </button>
        </div>
        <button class="submit-button" @click="gotoPay" :disabled="!selectedAmount">立即支付</button>
      </div>
    </div> -->

    <div class="container">
      <div class="recharge-container">
        <div class="package-intro">
          <h3>充值套餐介绍</h3>
          <div class="package-cards">
            <div :class="{ active: selectedAmount === item.f2502 }"
              @click="selectAmount(item.f2502)"
              v-for="item in rechargeForm" :key="item.f2501" class="package-card">
              <h4>¥{{ item.f2502 }}</h4>
              <p>token数：{{ item.f2503 }}</p>
              <p>{{ item.f2504 }}</p>
            </div>
          </div>
        </div>

        <div class="recharge-panel">
          <!-- <h3>充值</h3> -->
          <!-- <div class="amount-options">
            <button class="amount-btn" v-for="amount in amounts" :key="amount"
              :class="{ active: selectedAmount === amount }" @click="selectAmount(amount)">
              ¥{{ amount }}
            </button>
          </div> -->
          <div class="pay-button">
            <button @click="gotoPay">立即支付</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { pay, recharge } from '@/api/pay'
import { listT25 } from "@/api/system/T25";
export default {
  name: "pay",
  data() {
    return {
      amounts: [10, 20, 50, 100, 300, 500],
      selectedAmount: 10,
      selectedPaymentMethod: '支付宝支付',
      alipayFormHtml: '', // 用于存储支付宝返回的表单HTML
      rechargeForm: {} // 用于存储充值套餐的数据
    }
  },
  created() {
    listT25().then(res => {
      this.rechargeForm = res.rows
    })
  },
  methods: {
    selectAmount(amount) {
      this.selectedAmount = amount;
    },
    gotoPay () {
      let params = {}
      recharge(this.selectedAmount).then(res => {
        params = res.data
        pay(params).then(res => {
          console.log(res)
          // window.open(`http://localhost:7519/alipay/pay?subject=${params.subject}&traceNo=${params.traceNo}&totalAmount=${params.totalAmount}`)
          window.open(`https://apiwx.peacezhwd.cn/alipay/pay?subject=${params.subject}&traceNo=${params.traceNo}&totalAmount=${params.totalAmount}`)
        })
      })
    },
  },
   mounted() {

  },
};
</script>
<style lang="scss" scoped>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

body {
  background-color: #f5f7fa;
  color: #333;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

.recharge-container {
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  padding: 30px;
}

.package-intro {
  margin-bottom: 30px;
}

.package-intro h3 {
  font-size: 18px;
  color: #333;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
}

.package-cards {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  .active {
      background-color: #4a90e2;
      border-color: #4a90e2;
    }
}

.package-card {
  width: calc(16.666% - 15px);
  background-color: #f9f9f9;
  border-radius: 8px;
  padding: 15px;
  text-align: center;
  margin-bottom: 15px;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.package-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.package-card h4 {
  font-size: 20px;
  color: #ff6b6b;
  margin-bottom: 10px;
}

.package-card p {
  font-size: 14px;
  color: #666;
}

.recharge-panel {
  text-align: center;
}

.recharge-panel h3 {
  font-size: 20px;
  color: #333;
  margin-bottom: 25px;
}

.amount-options {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 25px;
}

.amount-btn {
  width: 80px;
  height: 40px;
  margin: 0 10px 10px;
  background-color: #f5f5f5;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.amount-btn:hover {
  background-color: #e9e9e9;
}

.pay-button {
  margin-top: 20px;
}

.pay-button button {
  width: 100%;
  height: 45px;
  background-color: #4a90e2;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.pay-button button:hover {
  background-color: #3a7bc8;
}
/*
.recharge-container {
  width: 400px;
  margin: 50px auto;
  border: 1px solid #ddd;
  padding: 20px;
  border-radius: 5px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.recharge-container h2 {
  text-align: center;
}

.warning {
  color: red;
  font-weight: bold;
  margin-bottom: 20px;
}

.amount-options {
  display: flex;
  justify-content: space-around;
  margin-bottom: 20px;
}

.amount-options button {
  padding: 5px 10px;
  border: none;
  background-color: #f0f0f0;
  cursor: pointer;
  border-radius: 3px;
}

.amount-options button.active {
  background-color: #000;
  color: #fff;
}

.payment-methods {
  margin-bottom: 20px;
}

.payment-methods label {
  display: block;
  margin-bottom: 10px;
}

.payment-methods input[type="radio"] {
  margin-right: 5px;
}

.submit-button {
  width: 100%;
  padding: 10px;
  background-color: #ccc;
  border: none;
  border-radius: 3px;
  cursor: pointer;
}

.submit-button:disabled {
  background-color: #ddd;
}

.tips {
  font-size: 12px;
  color: #666;
} */
</style>
